//
//  Handle_DealWaitHandle_Task.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-6-19.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "Handle_DealWaitHandle_Task.h"
#import "Mail_Send_Task.h"
#import "SingleFile.h"

@implementation Handle_DealWaitHandle_Task

-(void)execute
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString* needHandWrite = [userDefaults objectForKey:Epoint_NeedHandWrite_Flag];
    NSString* CanPDFSign = [userDefaults objectForKey:@"CanPDFSign"];
    NSString *writeSginType = NSLocalizedString(@"writeSginType", @"");
    //        "writeSginType" = "1";//1pdf 2笔迹
    if ([@"true" isEqualToString:[needHandWrite lowercaseString]]&&[writeSginType isEqualToString:@"1"]&&[CanPDFSign isEqualToString:@"1"]) {
            if (![self upLoadPdfFile]) {
                [self exeFailureWithMessage:@"文件上传失败"];
                return;
            }
    }

    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");

    
    EpointWebServiceUtil *webserviceHelper = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"Handle_DealWaitHandle"];

    
    NSString *ParasXml = [params objectForKey:@"ParasXml"];
//    ParasXml = [EpointStringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    NSLog(@"bs=%@",bs);
    if ([self validateXMLWS:bs]) {
        [self exeSuccessWithData:bs];
    }
}

-(BOOL)upLoadPdfFile{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    

    Mail_Send_Task *fileUpLoadTask = [[Mail_Send_Task alloc] init];
    SingleFile *file = [[SingleFile alloc] init];
    file.AttachGuid =[params objectForKey:@"MessageItemGuid"];
    file.ATTACHFILENAME = @"PDF.pdf";
    file.fileData=[userDefaults objectForKey:Epoint_NeedHandWrite_NSData];
    NSMutableArray* list = [[NSMutableArray alloc] init];
    [list addObject:file];
    
    return [fileUpLoadTask upLoadAttachFile:list :@"" :@"PDF"];
}

@end
